import requests
import json
import hashlib

APP_ID = 20170810000071620
CODE = 'mjENLxcFfmc3K3QnxlOS'
SALT = 1435660288

query = 'test'

s = str(APP_ID) + query + str(SALT) + CODE

md5 = hashlib.md5()
md5.update(bytes(s, 'utf8'))
# print(md5.hexdigest())
payload_match = {
    'q': query,
    'from': 'en',
    'to': 'zh',
    'appid': int(APP_ID),
    'salt': SALT,
    'sign': md5.hexdigest()


}

r_match = requests.post('http://api.fanyi.baidu.com/api/trans/vip/translate', json=payload_match, timeout=200)
a_match = r_match.json()
print("2\n")
print(json.dumps(a_match, indent=4, sort_keys=True, ensure_ascii=False))
